<template>
  <div class="content">
    <el-form inline :model="form">
      <el-form-item label="开始时间">
        <el-date-picker
          type="datetime"
          placeholder="选择开始时间"
          v-model="form.startTime"
          size="mini"
          default-time="00:00:00"
          :picker-options="pickerOptions0"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间">
        <el-date-picker
          type="datetime"
          placeholder="选择结束时间"
          v-model="form.endTime"
          size="mini"
          :picker-options="pickerOptions0"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="统计时间类型">
        <el-select v-model="form.timeType" size="mini">
          <el-option label="每10分钟" value="10m"></el-option>
          <el-option label="每1小时" value="1h"></el-option>
          <el-option label="每2小时" value="2h"></el-option>
          <el-option label="每6小时" value="6h"></el-option>
          <el-option label="每12小时" value="12h"></el-option>
          <el-option label="每24小时" value="24h"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="mini" @click="search">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="list" stripe style="width: 100%">
      <el-table-column
        label="监测站点"
        prop="monitorName"
        align="center"
        min-width="65%"
      ></el-table-column>
      <el-table-column
        label="WGS84-H(m)"
        prop="dataH"
        align="center"
      ></el-table-column>
      <el-table-column
        label="WGS84-x(m)"
        prop="dataGx"
        align="center"
      ></el-table-column>
      <el-table-column
        label="WGS84-y(m)"
        prop="dataGy"
        align="center"
      ></el-table-column>
      <el-table-column
        label="WGS84-ΔH(mm)"
        prop="totalH"
        align="center"
      ></el-table-column>
      <el-table-column
        label="WGS84-ΔP(mm)"
        prop="totalP"
        align="center"
      ></el-table-column>
      <el-table-column
        label="WGS84-ΔX(mm)"
        prop="totalX"
        align="center"
      ></el-table-column>
      <el-table-column
        label="WGS84-ΔY(mm)"
        prop="totalY"
        align="center"
      ></el-table-column>
      <el-table-column
        label="WGS84-VH(mm/24h)"
        prop="ghSpeed"
        align="center"
      ></el-table-column>
      <el-table-column
        label="WGS84-Vx(mm/24h)"
        prop="gxSpeed"
        align="center"
      ></el-table-column>
      <el-table-column
        label="WGS84-Vy(mm/24h)"
        prop="gySpeed"
        align="center"
      ></el-table-column>
      <el-table-column
        label="统计数量"
        prop="dataCount"
        align="center"
        min-width="60%"
      ></el-table-column>
      <el-table-column
        label="统计时间"
        prop="theDate"
        align="center"
      ></el-table-column>
    </el-table>
    <el-row type="flex" justify="end">
      <!-- <el-col :span="23"> -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="query.page"
        :page-sizes="[5, 10]"
        :page-size="query.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
      <!-- </el-col> -->
    </el-row>
  </div>
</template>

<script>
import moment from "moment";
import { getBdDataByPage } from "../../../../api/Monitoring";

export default {
  name: "DataStatistics",
  props: {
    node: Object,
  },
  data() {
    return {
      query: {
        page: 1,
        pagesize: 10,
      },
      form: {
        startTime: moment().subtract(2, "months").format("YYYY-MM-DD 00:00:00"),
        endTime: moment().format("YYYY-MM-DD HH:mm:ss"),
        timeType: "10m",
      },
      pickerOptions0: {
        disabledDate(time) {
          return time.getTime() > Date.now(); //如果没有后面的-8.64e6就是不可以选择今天的
        },
      },
      total: null,
      list: [],
    };
  },
  methods: {
    async getDataList() {
      let queryData = {
        startTime: moment(this.form.startTime).format("YYYY-MM-DD HH:mm:ss"),
        endTime: moment(this.form.endTime).format("YYYY-MM-DD HH:mm:ss"),
      };
      const res = await getBdDataByPage({
        monitorCode: this.node.monitorCode,
        monitorId: this.node.id,
        pageCount: this.query.page,
        pageSize: this.query.pagesize,
        endTime: queryData.endTime,
        startTime: queryData.startTime,
        timeType: this.form.timeType,
      });
      console.log(res);
      if (res.resultCode == "200") {
        console.log(res);
        this.total = res.parameter.total;
        this.list = res.parameter.list;
        for (let i = 0; i < this.list.length; i++) {
          this.list[i].monitorName = this.node.name;
        }
        this.list.forEach((item) => {
          item.dataH = Number(item.dataH).toFixed(3);
          item.dataGx = Number(item.dataGx).toFixed(3);
          item.dataGy = Number(item.dataGy).toFixed(3);
          item.totalH = Number(item.totalH).toFixed(3);
          item.totalY = Number(item.totalY).toFixed(3);
          item.totalX = Number(item.totalX).toFixed(3);
          item.totalP = Number(item.totalP).toFixed(3);
          item.gySpeed = Number(item.gySpeed).toFixed(3);
          item.ghSpeed = Number(item.ghSpeed).toFixed(3);
          item.gxSpeed = Number(item.gxSpeed).toFixed(3);
        });
      } else if (res.resultCode == "204") {
        this.query.page = 1;
        this.query.pagesize = 5;
        this.$message({
          message: "暂无数据",
          offset: 450,
          duration: 1000,
        });
      }
    },
    search() {
      this.getDataList();
    },
    handleSizeChange(val) {
      this.query.pagesize = val;
      this.getDataList();
    },
    handleCurrentChange(val) {
      this.query.page = val;
      this.getDataList();
    },
  },
  created() {
    this.getDataList();
  },
};
</script>

<style scoped>
.content {
  height: 83vh;
  overflow: auto;
}

.el-form-item {
  margin-bottom: 0;
}
.el-table-box {
  display: block;
  height: 70vh;
  overflow-y: auto;
  margin-bottom: 20px;
}
.el-table::before {
  z-index: inherit;
}
</style>